<?php
/**
 * Created by JetBrains PhpStorm.
 * User: WEI JIAN XIANG
 * Date: 8/6/13
 * Time: 9:48 PM
 * To change this template use File | Settings | File Templates.
 */

class PortController extends Core_Controller_Action
{
    public function indexAction()
    {
        $main_ports_db = new Core_Model_DbTable_MainPorts();
        $this->view->ports = $main_ports_db->getGroups();
        
        if("mobile" == Core_MobileDetect::getCurrentDevice()) {
            $this->_helper->layout()->setLayout('layout_mobile');
            $this->render("indexmobile");
            return;
        }
    }

    public function tideAction(){
        $tide_ports_db = new Core_Model_DbTable_TidePorts();
        $this->view->ports = $tide_ports_db->getGroups();

        if("mobile" == Core_MobileDetect::getCurrentDevice()) {
            $this->_helper->layout()->setLayout('layout_mobile');
            $this->render("tidemobile");
            return;
        }
    }

    public function tidedetailAction() {
        $id = $this->_getParam("id");
        if ( !$id )
        {
            exit();
        }
        $tide_port_db = new Core_Model_DbTable_TidePorts();
        $cond = $tide_port_db->getAdapter()->quoteInto("id = ?", $id);
        $tide_port = $tide_port_db->fetchRow($cond);
        if ( !$tide_port )
        {
            exit(0);
        }
        header('Location: ' . UPLOAD_URL . $tide_port['file']);
        exit(0);
    }
    
    public function detailAction() {
        $id = $this->_getParam("id");
        if ( !$id )
        {
            exit();
        }
        $main_port_db = new Core_Model_DbTable_MainPorts();
        $cond = $main_port_db->getAdapter()->quoteInto("id = ?", $id);
        $main_port = $main_port_db->fetchRow($cond);
        if ( !$main_port )
        {
            exit(0);
        }
        header('Location: ' . UPLOAD_URL . $main_port['file']);
        exit(0);
    }
}